package com.qianfeng.smartdevice.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by wenka on 2022/3/27 13:56
 *
 * @author wenkaixin
 * @version 1.0
 * @since 1.0
 */
@EnableScheduling
@Component
public class DeviceStatusCheckEvent {
    private ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    @Scheduled(fixedRate=45000)
    public void checkStatus() {
        //检查设备的最后一次时间, 遍历所有的设备,告诉websocket你该检查设备了
        context.publishEvent(new DeviceStatusCheckEvent());
    }
}
